requestScreenCapture();
access_token = "24.34f08ac0e80a74c1874ab930743d0852.2592000.1724917015.282335-100642768";
//access_token=console.rawInput("输入access_token");
console.show()
while (true) {
    path = console.rawInput("随便输入什么点击确定识别当前屏幕文字");
    console.clear();
    path = "/sdcard/test.png";
    let start = Date.now();
    console.hide()
    captureScreen(path)
    console.show()
    str = getimgtext(path, access_token);
    console.log('识别耗时', (Date.now() - start) / 1000)
}

function getimgtext(path, access_token) {
    url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=" + access_token;
    var img = getbase64(path);
    var res = http.post(url, {
        image: img
    }, {
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        }
    });
    img = "null";
    var html = res.body.json();
    console.log('识别条数', html.words_result_num)
    console.log(html.words_result)

    return html;
}
function getbase64(path) {
    var oin = null;
    oin = new java.io.FileInputStream(path);
    var lt = oin.available();
    var data = java.lang.String((new Array(lt + 1) + "")).getBytes();
    lt = oin.read(data);
    return java.lang.String((android.util.Base64.encode(data, 0)));

}